package cpr.view;

import java.awt.Dimension;
import java.rmi.RemoteException;
import java.util.ArrayList;
import java.util.List;

import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;

import cpr.controller.ClienteCprRMI;
import bean.vo.ProveedorVO;;


@SuppressWarnings("serial")
public class PanelTablaProveedores extends JPanel {

	public PanelTablaProveedores() {
        String[] columnNames = { "Id", "Nombre" };
        
        List<ProveedorVO> proveedores = new ArrayList<ProveedorVO>();
		try {
			proveedores = ClienteCprRMI.getInstance().getIRemota().getProveedores();
		} catch (RemoteException e) {
			JOptionPane.showMessageDialog(this, "Error en la carga de proveedores. " + e.getMessage(), 
					"Error en la carga de datos", JOptionPane.WARNING_MESSAGE);
		}
        
        Object[][] data = new Object[proveedores.size()][2];
        int i = 0;
        for (ProveedorVO prov : proveedores) {
            data[i][0] = prov.getCuit();
            data[i][1] = prov.getRazonSocial();
            i++;
        }

        final JTable table = new JTable(data, columnNames);
        table.setPreferredScrollableViewportSize(new Dimension(450,300));
        table.setFillsViewportHeight(true);
        
        //Create the scroll pane and add the table to it.
        JScrollPane scrollPane = new JScrollPane(table);
        
        //Add the scroll pane to this panel.
        add(scrollPane);
        scrollPane.setBounds(0, 0, 100, 100);
    }
}